// packageB/pages/perform/performDetail/performDetail.js
var common = require("../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 1,
        performDetail:{}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onClickIcon() {
        Toast('点击图标');
      },

      onClickButton() {
        Toast('点击按钮');
      },
    // 点击按钮转换

    onLoad: function (options) {
      let capsule = wx.getMenuButtonBoundingClientRect()
      this.setData({
        height: capsule.height,
        top: capsule.top, 
        id:options.id ? options.id :'',
        storeId:options.storeId ? options.storeId :'',
      },()=>{
        // 演出门票详情
        this.perform_list()
      })
     
    },
    // 
    time(time) {
      return common.dateFormat('yyyy-MM-dd HH:mm', time)
    },
      // 演出门票详情
      perform_list(){
        var that = this
        const tempJson = {
          storeId: that.data.storeId,
          storePerformId: that.data.id,
      }
      common.post('/storePerform/getStorePerformDetail', tempJson, res => {
         res.data.holdingEndTime=that.time(res.data.holdingEndTime)
         res.data.holdingStartTime=that.time(res.data.holdingStartTime)
         var jsonDa = JSON.stringify(res.data.detailImgs).replace(/<img/gi, "<img class='richImg'style='width:auto!important;height:auto!important;max-height:100%;width:100%;'");
         //遍历得到的数据，给img添加CSS和style
         var newResData = JSON.parse(jsonDa);
         var jsonDas = JSON.stringify(res.data.notice).replace(/<img/gi, "<img class='richImg'style='width:auto!important;height:auto!important;max-height:100%;width:100%;'");
         //遍历得到的数据，给img添加CSS和style
         var newResDatas = JSON.parse(jsonDas);
          that.setData({
            performDetail:res.data,
            details_nei :newResData,
            details_neis :newResDatas
          })
      })
      },
      goBack() {
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        } else {
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },
      // 立即购买
      toBookPage(e) { // 立即预订
     
        wx.navigateTo({
          url: '/packageA/pages/performs/performssession/performssession?storePerformId=' + this.data.id +
          '&ticketName=' + this.data.performDetail.title +
          '&storeName=' + this.data.performDetail.storeName+
          '&storeId=' + this.data.storeId  +
          '&holdingAddress=' + this.data.performDetail.holdingAddress ,
        })
      },
      toStore() { //跳转店铺
      
        wx.navigateTo({
          url: '/pages/ScenicArea/ScenicAreaMainPage/index?id=' +  this.data.storeId
        })
      },
      // 点击定位
      click_address(){
        if (!this.data.performDetail.xpoint || !this.data.performDetail.ypoint) {
            common.showToast('商家未设置位置信息')
            return
        }
        let lon = parseFloat(this.data.performDetail.xpoint)
        let lat = parseFloat(this.data.performDetail.ypoint)
        wx.openLocation({
            latitude: lon,
            longitude:lat,
            scale: 18,
            fail: () => {
                wx.showToast({
                    title: '无地址信息',
                    icon: "none"
                })
            }
        })
    },
    callPhone() {
      wx.makePhoneCall({
        phoneNumber: this.data.performDetail.mobile,
        fail: function (res) { }
      })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})